<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta charset="utf-8" />
		<title>用户登录</title>
		<link rel="stylesheet" href="assets/libs/layui/css/layui.css" />
		<link rel="stylesheet" href="assets/libs/layui/css/modules/layer/default/layer.css" />
		<link rel="stylesheet" href="assets/css/login.css" media="all">
	</head>

	<body>
		<div class="login-wrapper">

			<div class="login-header">
				<img src="assets/images/sungologo.png"> 松果健康
			</div>

			<div class=" login-body">
				<div class="layui-card">
					<div class="layui-card-header">
						<i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
					</div>
					<div class="layui-card-body layui-form layui-form-pane">
						<div class="layui-form-item">
							<label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
							<div class="layui-input-block">
								<input name="username" id="username" type="text" lay-verify="required" placeholder="账号" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
							<div class="layui-input-block">
								<input name="password" id="password" type="password" lay-verify="required" placeholder="密码" class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<button lay-filter="login-submit" id="logio" class="layui-btn layui-btn-fluid" lay-submit>登 录</button>
						</div>

					</div>
				</div>
			</div>

			<div class="login-footer">
				<p>© 2018
					<a href="javascript:;" target="_blank">北京正气和健康科技有限公司</a>
				</p>

			</div>
		</div>

		<script type="text/javascript" src="assets/libs/jquery-3.2.1.min.js"></script>
		<script type="text/javascript" src="assets/libs/layui/layui.js"></script>
		<script type="text/javascript" src="module/common.js"></script>
		<script type="text/javascript" src="assets/libs/layui/lay/modules/layer.js" ></script>
		<script>
			$("#logio").click(function() {
				var u = $("#username").val()
				var p = $("#password").val()
				$.ajax({
					type: "POST",
					url: loginPath,
					data: {
						username: u,
						password: p
					},
					dataType: "json",
					xhrFields: {
						withCredentials: true
					},

					success: function(data) {
						layer.closeAll('loading');
						if(data.code == 0) {

							$.ajax({
								type: "POST",
								url: adminPath,
								data: {},
								dataType: "json",
								xhrFields: {
									withCredentials: true
								},
								success: function(datas) {
									localStorage.setItem("login_info", JSON.stringify(datas.user));
									location.replace('./');
								},
								error: function(result) {
									console.log(result);
								},
							});

						} else if(data.code == 500) {
							layer.msg(data.msg, {
								icon: 5
							});
						}
						console.log(data)
					},
					error: function(result) {
						layer.closeAll('loading');
					},
				});

			})
		</script>
	</body>

</html>